import {Router} from 'express';
import SyncService from '../service/sync';

var net = require('net');

const syncRouter = Router();

syncRouter.get('/', async (req, res) => {
    const syncs = await new SyncService().findAll();
    res.json(syncs);
});

syncRouter.get('/:id', async (req, res) => {
    // const sync = await new SyncService().findOne(parseInt(req.params.id));
    // res.json(sync);
});

syncRouter.post('/', async (req, res) => {
    console.log(req.body)
    // const sync = await new SyncService().create(req.body);
    // res.json(sync);
});

syncRouter.post('/open', async (req, res) => {
    console.log('准备开启同步服务。。。。。。。')
    await new SyncService().openSync();
    // const sync = await new SyncService().create(req.body);
    res.json({message: 'Sync open successfully'});
});

syncRouter.put('/:id', async (req, res) => {
    // console.log('update--->', parseInt(req.params.id), req.body)
    const sync = await new SyncService().update(parseInt(req.params.id), req.body);
    res.json({message: 'Sync successfully'});
});

syncRouter.delete('/:id', async (req, res) => {
    // await new SyncService().delete(parseInt(req.params.id));
    // res.json({message: 'Deleted successfully'});
});

export default syncRouter;
